export default {
  data() {
    return {
      taskRunning: false,
      taskList: []
    }
  },
  computed: {
    parent() {
      return this.$parent
    },
    stageSize() {
      return this.parent.stageSize
    },
    markList() {
      return this.parent.markList
    },
    alwaysShowMarkTypes() {
      return this.parent.alwaysShowMarkTypes
    },
    dataList() {
      return this.parent.dataList
    },
    markShow() {
      return this.parent.markShow
    },
    scale() {
      return this.parent.scale
    },
    eventBus() {
      return this.parent.eventBus
    },
    moveTask() {
      return this.parent.moveTask
    },
    pointerType() {
      return this.parent.pointerType
    },
    selectionBgColor() {
      return this.parent.selectionBgColor
    },

    maxWidth: {
      get() {
        return this.parent.maxWidth
      },
      set(val) {
        if (val < this.parent.maxWidth) return
        this.parent.maxWidth = val
      }
    },
    maxHeight: {
      get() {
        return this.parent.maxHeight
      },
      set(val) {
        if (val < this.parent.maxHeight) return
        this.parent.maxHeight = val
      }
    },
    // 方法
    getWords() {
      return this.parent.getWords
    },
    clearSelection() {
      return this.parent.clearSelection
    },
    openMask() {
      return this.parent.openMask
    },
    handleStageMousedown() {
      return this.parent.handleStageMousedown
    },
    handleStageContextmenu() {
      return this.parent.handleStageContextmenu
    },
    addMark() {
      return this.parent.addMark
    },
    getWordByIndexPos() {
      return this.parent.getWordByIndexPos
    },
    getWordByPointerPosition() {
      return this.parent.getWordByPointerPosition
    },
    getWrodsAToB() {
      return this.parent.getWrodsAToB
    },
    getPos() {
      return this.parent.getPos
    },
    sendEvent() {
      return this.parent.sendEvent
    },
    getSelection() {
      return this.parent.getSelection
    },
    handleMoveImage() {
      return this.parent.handleMoveImage
    },
    getImgSrc() {
      return this.parent.getImgSrc
    },
    getText() {
      return this.parent.getText
    },
  },
  methods: {

    addTask(task) {
      let index = this.taskList.findIndex(item => item === task)
      if (index > -1) this.taskList.splice(index, 1)
      this.taskList.push(task)
      this.runTask()
    },
    async runTask() {
      if (this.taskRunning) return
      this.taskRunning = true
      let task = this.taskList.shift()
      if (!task) return this.taskRunning = false
      await task()
      this.taskRunning = false
      this.runTask()

    }
  }
}
